package com.bdk.middle.orchestration.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RedissonConfig {

    /**
     * 哨兵模式
     */
    /*@Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() {
        Config config = new Config();
        SentinelServersConfig serverConfig = config.useSentinelServers()
                .addSentinelAddress("redis://127.0.0.1:26379", "redis://127.0.0.1:26380", "redis://127.0.0.1:26381")
                .setMasterName("mymaster")
                .setReadMode(ReadMode.SLAVE)
                .setTimeout(20000);
        return Redisson.create(config);
    }*/

    /**
     * 单机模式
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redissonSingle() {
        Config config = new Config();
        SingleServerConfig serverConfig = config.useSingleServer()
                .setAddress("redis://127.0.0.1:6379")
                .setTimeout(2000)
                .setConnectionPoolSize(64)
                .setConnectionMinimumIdleSize(10);

        return Redisson.create(config);

    }

}